package com.rsk.api.curriculum;


import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.aop.ParamCheck;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.curriculum.RskCourseService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import com.rsk.utils.tools.PageUtils;

@RestController
@RequestMapping(value="/rsk/course")
public class RskCourseApi {
	
	@Reference(interfaceClass = RskCourseService.class, protocol = "dubbo")
	private RskCourseService rskCourseService;
	
	
	//@RequiresPermissions("coursecategory:save")
	@PostMapping(value="/saveRskCourse" )
	public Result<String> saveRskCourse(
			@QueryParam("categoryId") @ParamCheck(notNull=true) Long categoryId,
		   	@QueryParam("courseName") @ParamCheck(notNull=true) String courseName,
		   	@QueryParam("courseIntroduction") @ParamCheck(notNull=true) String courseIntroduction,
		   	@QueryParam("courseUrl") @ParamCheck(notNull=true) String courseUrl,
		   	@QueryParam("courseCover") @ParamCheck(notNull=true) String courseCover,
		   	@QueryParam("isRecommend") @ParamCheck(notNull=true) Integer isRecommend,
		   	@QueryParam("isOriginal") @ParamCheck(notNull=true) Integer isOriginal,
		   	@QueryParam("isSee") @ParamCheck(notNull=true) Integer isSee,
		   	@QueryParam("courseSource") @ParamCheck(notNull=true) Integer courseSource,
		   	@RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseService.saveRskCourse(categoryId, courseName, courseIntroduction, courseUrl, 
				courseCover, isRecommend, isOriginal, isSee, courseSource, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:update")
	@PostMapping(value="/updateRskCourse" )
	public Result<String> updateRskCourse(@QueryParam("id") @ParamCheck(notNull=true) Long id,
										       @QueryParam("categoryName") @ParamCheck(notNull=true) String categoryName,
										       @QueryParam("sort") @ParamCheck(notNull=true) Integer sort,
									           @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		//int i = rskCourseService.updateRskCourse(id, categoryId, courseName, courseIntroduction, courseUrl, courseCover, isRecommend, isOriginal, isSee, operatorUser)
		int i = 0;
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:del")
	@PostMapping(value="/delRskCourse" )
	public Result<String> delRskCourse(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									   @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseService.delRskCourse(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateRskCourseStatus" )
	public Result<String> updateRskCourseStatus(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									            @QueryParam("courseStatus") @ParamCheck(notNull=true) Integer courseStatus,
									            @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseService.updateRskCourseStatus(id, courseStatus, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateRskCourseRecommend" )
	public Result<String> updateRskCourseRecommend(@QueryParam("id") @ParamCheck(notNull=true) Long id,
												   @QueryParam("isRecommend") @ParamCheck(notNull=true) Integer isRecommend,
												   @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseService.updateRskCourseRecommend(id, isRecommend, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateRskCourseSee" )
	public Result<String> updateRskCourseSee(@QueryParam("id") @ParamCheck(notNull=true) Long id,
												   @QueryParam("isSee") @ParamCheck(notNull=true) Integer isSee,
												   @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseService.updateRskCourseSee(id, isSee, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}

	@SuppressWarnings("rawtypes")
	@PostMapping(value="/selectCourseCategory" )
	public Result<PageUtils> selectCourseCategory(
			@QueryParam("nowPage") @ParamCheck(notNull=true) Integer nowPage,
			@QueryParam("pageSize") @ParamCheck(notNull=true) Integer pageSize,
			@QueryParam("categoryName") String categoryName,
			@RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		//PageUtils page = courseCategoryService.selectCourseCategory(categoryName, nowPage, pageSize);
		//return ResultBuilder.success(page, ResultCode.SUCCESS);
		return null;
	}
}
